/**
 * \file dmxcon/device.h
 * \author Christian Spoo
 * \date 01.08.2010
 *
 * DMX512 host device handling
 */

#ifndef __DMXCON__DEVICE_H__
#define __DMXCON__DEVICE_H__

#ifdef __cplusplus
extern "C" {
#endif

/*! \brief Forward declaration for struct device_t
 */
struct device_t;

/*! \brief DMX512 host device descriptor operations
 *
 *  Contains function pointers to driver functions
 */
struct device_ops_t {
  /*! \brief Destroy operation
   */
  int (*destroy)(struct device_t *device);

  /*! \brief Refresh operation
   */
  int (*refresh)(struct device_t *device);

  /*! \brief Set range operation
   */
  int (*set_range)(struct device_t *device, unsigned short end_addr);

  /*! \brief Set channel operation
   */
  int (*set_channel)(struct device_t *device, unsigned short channel, unsigned char value);
};


/*! \brief DMX512 host device structure
 *
 *  This structure contains all information necessary for the driver to control the DMX512 device.
 */
struct device_t {
  /*! \brief Device filename
   */
  char *devfile;

  /*! \brief Controlling file descriptor. Only used by devices that are controlled via device files
   */
  int ctrl_fd;

  /*! \brief Last address this device should output
   */
  unsigned int end_addr;

  /*! \brief Device operations
   */
  struct device_ops_t ops;
};

struct device_t *device_create(void);
int device_destroy(struct device_t *device);

int device_set_range(struct device_t *device, unsigned short end_addr);
int device_set_channel(struct device_t *device, unsigned short channel, unsigned char value);
int device_refresh(struct device_t *device);

#ifdef __cplusplus
}
#endif

#endif

